<template>
<h1>El-表格组件</h1>
  <el-table :data="tableData" stripe style="width: 100%">
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
  </el-table>
  <el-table :data="arr" stripe style="width: 100%">
    <el-table-column type="index" width="80" align="center" label="编号"/>
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="salary" label="Salary" width="180" />
    <el-table-column prop="job" label="Job" />
    <el-table-column label="操作">
    <template #default="scope">
      <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
    </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";

const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]

// 定义数组用来保存表格数据
const arr = ref([
  {name: '张三',salary: 10000, job: '维修员' },
    {name: '李四',salary: 20000, job: '维修员' },
    {name: '王五',salary: 30000, job: '维修员' },
    {name: '赵六',salary: 40000, job: '维修员' },
]);
const del = (index,emp) => {
  if (confirm(`确定删除${emp.name}吗？`)){
    arr.value.splice(index,1);
  }
}
</script>

<style scoped>

</style>